package net.peelmeagrape.hibernate;

import net.peelmeagrape.hibernate.xmlgen.XmlAttribute;
import net.peelmeagrape.hibernate.xmlgen.XmlElement;
import net.peelmeagrape.hibernate.xmlgen.AddPropertyNameAsAttribute;

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Target;

/**
 * Equivalent to {@link Version} with type="timestamp".
 */
@Target({METHOD,FIELD}) @Retention(RUNTIME)
@XmlElement(name="timestamp")
@AddPropertyNameAsAttribute(name="name")
public @interface Timestamp
{
    Meta[] meta() default {};
    @XmlAttribute String node() default "";
    /**
     * The strategy Hibernate should use for accessing the property value. This may be one of
     * 'property', 'field', 'embedded', or the name of a subclass of {@link org.hibernate.property.PropertyAccessor}.
     */
    @XmlAttribute String access() default "property";
    @XmlAttribute String column() default "";
    @XmlAttribute("unsaved-value") UnsavedValue unsavedValue() default UnsavedValue.UNDEFINED;

    /**
     * What value of the field represents an unsaved entity.
     */
    public static enum UnsavedValue
    {
        NULL("null"),
        UNDEFINED("undefined");
        private String value;

        UnsavedValue(String value)
        {
            this.value = value;
        }

        public String toString()
        {
            return value;
        }
    }

}
